<% add_decidim_page_title(t("decidim.forms.admin.questionnaires.edit_questions.title")) %>

<% if templates_defined? && choose_template? %>
  <%= render partial: "decidim/templates/admin/questionnaire_templates/choose", locals: { target: questionnaire, form_title: t("decidim.forms.admin.questionnaires.edit.title"), show_buttons: true } %>
<% else %>

  <div class="questionnaire-questions">
    <div class="item_show__header">
      <h1 class="item_show__header-title">
        <%= t("decidim.forms.admin.questionnaires.edit_questions.title") %>
          <% if questionnaire.questions_editable? %>
            <button class="button button__sm button__secondary add-question"><%= t("add_question", scope: "decidim.forms.admin.questionnaires.edit_questions") %></button>
            <button class="button button__sm button__secondary add-separator"><%= t("add_separator", scope: "decidim.forms.admin.questionnaires.edit_questions") %></button>
            <button class="button button__sm button__secondary add-title-and-description"><%= t("add_title_and_description", scope: "decidim.forms.admin.questionnaires.edit_questions") %></button>
          <% end %>
          <% if allowed_to? :preview, :questionnaire %>
            <%= link_to t("preview", scope: "decidim.forms.admin.questionnaires.form"), public_url, class: "button button__sm button__transparent-secondary", target: :_blank, data: { "external-link": false } %>
          <% end %>
          <% if questionnaire.responses.any? %>
            <%= export_dropdown(current_component, questionnaire.id) if allowed_to? :export_responses, :questionnaire %>
            <% if allowed_to? :show, :questionnaire_responses %>
              <%= link_to t("actions.show", scope: "decidim.forms.admin.questionnaires"), questionnaire_participants_url, class: "button button__sm button__secondary new whitespace-nowrap" %>
            <% end %>
          <% else %>
            <button class="button button__sm button__secondary whitespace-nowrap" disabled><%= t("empty", scope: "decidim.forms.admin.questionnaires.responses") %></button>
          <% end %>
      </h1>
    </div>
  </div>

  <div class="item__edit item__edit-1col">
    <div class="item__edit-form">
      <%= decidim_form_for(@form, url: update_questions_meeting_registrations_form_path(meeting_id: meeting.id), method: :patch, html: { class: "form-defaults form edit_questions_survey" }) do |form| %>
        <%= render partial: "decidim/forms/admin/questionnaires/questions_form", object: form %>
        <div class="item__edit-sticky">
          <div class="item__edit-sticky-container">
            <%= form.submit t("save", scope: "decidim.forms.admin.questionnaires.edit"), class: "button button__sm button__secondary" %>
          </div>
        </div>
      <% end %>
    </div>
  </div>

<% end %>
